﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "logger.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(&Logger::Instance(), &Logger::log_msg, this, &MainWindow::recive_log);

    mytimer = new myTimer;
    thread = new QThread;
    mytimer->moveToThread(thread);//!<多线程运行
    connect(thread, &QThread::finished, mytimer, &QObject::deleteLater);
    thread->start();
}

MainWindow::~MainWindow()
{
    if(thread->isRunning())
        thread->quit();
    delete ui;
}

void MainWindow::showEvent(QShowEvent *e)
{
    Q_UNUSED(e);
    ui->textBrowser->append(QDateTime::currentDateTime().toString("hh::mm:ss zzz ") + "mainwindow thread:" + QString::number((qint64)QThread::currentThreadId()));
}

void MainWindow::recive_log(const QString& msg)
{
    ui->textBrowser->append(msg);
}

